package org.dromara.Nyt7PlotDetailInfo.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.Nyt7PlotDetailInfo.domain.vo.Nyt7PlotDetailInfoExVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.Nyt7PlotDetailInfo.domain.vo.Nyt7PlotDetailInfoVo;
import org.dromara.Nyt7PlotDetailInfo.domain.bo.Nyt7PlotDetailInfoBo;
import org.dromara.Nyt7PlotDetailInfo.service.INyt7PlotDetailInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 地块详细信息
 *
 * @author Lion Li
 * @date 2024-12-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Nyt7PlotDetailInfo/Nyt7PlotDetailInfo")
public class Nyt7PlotDetailInfoController extends BaseController {

    private final INyt7PlotDetailInfoService nyt7PlotDetailInfoService;


    /**
     * 查询地块详细信息列表
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:list")
    @GetMapping("/list")
    public TableDataInfo<Nyt7PlotDetailInfoExVo> list(Nyt7PlotDetailInfoBo bo, PageQuery pageQuery) {
        return nyt7PlotDetailInfoService.queryPageList(bo, pageQuery);
    }


    /**
     * 导出地块详细信息列表
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:export")
    @Log(title = "地块详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Nyt7PlotDetailInfoBo bo, HttpServletResponse response) {
        List<Nyt7PlotDetailInfoVo> list = nyt7PlotDetailInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "地块详细信息", Nyt7PlotDetailInfoVo.class, response);
    }

    /**
     * 获取地块详细信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:query")
    @GetMapping("/{id}")
    public R<Nyt7PlotDetailInfoExVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        Nyt7PlotDetailInfoExVo vo =nyt7PlotDetailInfoService.queryByIdEx(id);
        return R.ok(vo);
        //return R.ok(nyt7PlotDetailInfoService.queryById(id));
    }

    /**
     * 新增地块详细信息
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:add")
    @Log(title = "地块详细信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Nyt7PlotDetailInfoBo bo) {
        return toAjax(nyt7PlotDetailInfoService.insertByBo(bo));
    }

    /**
     * 修改地块详细信息
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:edit")
    @Log(title = "地块详细信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Nyt7PlotDetailInfoBo bo) {
        return toAjax(nyt7PlotDetailInfoService.updateByBo(bo));
    }

    /**
     * 删除地块详细信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:remove")
    @Log(title = "地块详细信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(nyt7PlotDetailInfoService.deleteWithValidByIds(List.of(ids), true));
    }






    /**
     * 导出选中的地块详细信息列表
     */
    @SaCheckPermission("Nyt7PlotDetailInfo:Nyt7PlotDetailInfo:export")
    @Log(title = "地块详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelected")
    public void exportSelected(@RequestBody List<Long> ids, HttpServletResponse response) {
        List<Nyt7PlotDetailInfoVo> list = nyt7PlotDetailInfoService.queryListByIds(ids);
        ExcelUtil.exportExcel(list, "地块详细信息", Nyt7PlotDetailInfoVo.class, response);
    }








}
